package org.dromara.system.api.services;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.utils.AssertUtils;
import org.dromara.system.api.feign.SystemDataScopeClient;
import org.springframework.stereotype.Service;

/**
 * @author: zhou shuai
 * @date: 2024/10/6 11:14
 * @version: v1
 */
@Slf4j
@Service("sysDataScopeClientApiService")
@RequiredArgsConstructor
public class SysDataScopeClientApiService {

    private final SystemDataScopeClient systemDataScopeClient;

    /**
     * 获取角色自定义权限语句
     *
     * @param roleId 角色ID
     * @return 返回角色的自定义权限语句，如果没有找到则返回 null
     */
    public String getRoleCustom(Long roleId) {
        R<String> roleCustomResult = systemDataScopeClient.getRoleCustom(roleId);
        AssertUtils.assertTrue(R.isSuccess(roleCustomResult), "获取角色自定义权限语句失败");
        return roleCustomResult.getData();
    }

    /**
     * 获取部门和下级权限语句
     *
     * @param deptId 部门ID
     * @return 返回部门及其下级的权限语句，如果没有找到则返回 null
     */
    public String getDeptAndChild(Long deptId) {
        R<String> deptPersResult = systemDataScopeClient.getDeptAndChild(deptId);
        AssertUtils.assertTrue(R.isSuccess(deptPersResult), "获取部门和下级权限语句失败");
        return deptPersResult.getData();
    }

}
